function getCookie(name) {
    // 获取 Cookie 字符串
    var strCookie = document.cookie;
    // 分割 Cookie 字符串
    var arrCookie = strCookie.split(";");
    // 遍历匹配
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0].trim() === name) {
            return arr[1];
        }
    }
    // 如果没有找到指定名称的 Cookie，返回空字符串
    return "";
}


function clearAllCookies() {
    document.cookie = '';
    document.cookie = 'expires=Thu, 01 Jan 1970 00:00:00 UTC; max-age=2592000; path=/';
}


function clearCookie(name) {
    document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
}

function deepClone(obj) {
    if (typeof obj !== 'object' || obj === null) {
        return obj;
    }
    let clone = Array.isArray(obj) ? [] : {};
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            clone[key] = deepClone(obj[key]);
        }
    }
    return clone;
}



/****
 示例const date = new Date();
const format = 'YYYY-MM-DD HH:mm:ss';
const formattedDate = dateFormat(date, format);
console.log(formattedDate); // 输出类似 "2022-08-31 12:34:56"
 */

function dateFormat(date, format) {
    const locale = navigator.userLanguage || navigator.language;
    const formatter = new Intl.DateTimeFormat('en-US', {
        year: format.includes('YYYY') ? 'numeric' : undefined,
        month: format.includes('MM') ? '2-digit' : undefined,
        day: format.includes('DD') ? '2-digit' : undefined,
        hour: format.includes('HH') ? '2-digit' : undefined,
        minute: format.includes('mm') ? '2-digit' : undefined,
        second: format.includes('ss') ? '2-digit' : undefined,
    });
    const parts = formatter.formatToParts(date);
    const formattedDate = format
        .replace('YYYY', parts.year)
        .replace('MM', parts.month)
        .replace('DD', parts.day)
        .replace('HH', parts.hour)
        .replace('mm', parts.minute)
        .replace('ss', parts.second);
    return formattedDate;
}

